package com.shd.edanpei.ui.adapter;

import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseQuickImageAdapter;
import com.shd.edanpei.bean.OrderListModel;
import com.shd.edanpei.enums.OrderTypeEnum;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by mc on 2018/9/18.
 * yang-wen-wen
 */

public class ShareOrderAdapter extends BaseQuickImageAdapter<OrderListModel> {

    public ShareOrderAdapter(Context context) {
        super(context, R.layout.item_shareorder);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderListModel item) {

        ImageView ivType = helper.getView(R.id.iv_type);
        ivType.setVisibility(View.INVISIBLE);
        TextView tvType = helper.getView(R.id.tv_type);
        ConstraintLayout constraintLsyout=helper.getView(R.id.constraintLsyout);
        if (item.getOrderType() == OrderTypeEnum.car.getKey()) {
            ivType.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_label_car));
            tvType.setText(OrderTypeEnum.car.getValue());
            constraintLsyout.setBackground(ContextCompat.getDrawable(mContext,R.drawable.kapian_cldd));
        } else if (item.getOrderType() == OrderTypeEnum.house.getKey()) {
            ivType.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_label_house));
            constraintLsyout.setBackground(ContextCompat.getDrawable(mContext,R.drawable.kaipian_zfdd));
            tvType.setText(OrderTypeEnum.house.getValue());
        } else if (item.getOrderType() == OrderTypeEnum.normal.getKey()) {
            ivType.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_label_common));
            constraintLsyout.setBackground(ContextCompat.getDrawable(mContext,R.drawable.kapian_cldd));
            tvType.setText(OrderTypeEnum.normal.getValue());

        }else if (item.getOrderType() == OrderTypeEnum.personal.getKey()) {
            ivType.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.xinyong));
            constraintLsyout.setBackground(ContextCompat.getDrawable(mContext,R.drawable.kapian_grxy));
            tvType.setText(OrderTypeEnum.personal.getValue());
        }else if (item.getOrderType() == OrderTypeEnum.enterprise.getKey()) {
            ivType.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.qiye));
            constraintLsyout.setBackground(ContextCompat.getDrawable(mContext,R.drawable.kapian_qysj));
            tvType.setText(OrderTypeEnum.enterprise.getValue());
        }

        helper
//                .setText(R.id.tv_status, StatusEnum.getMeDes(item.getOrderStatus()))
                .setText(R.id.tv_name, item.getCustomerName2())
                .setText(R.id.tv_time, item.getCreateTime())
                .setText(R.id.tv_info, item.getCustomerName2()+item.getInfo())
                .setText(R.id.tag2, "订单金额："+item.getApplyAmount())
                .setText(R.id.tag5,"此单成交即可获取"+item.getEstimatedRevenue())
                .addOnClickListener(R.id.tv_take);

        if (!TextUtils.isEmpty(item.getAvatarUrl())) {
            mLoadImgCtrl.getGlide().load(item.getAvatarUrl()).into((CircleImageView) helper.getView(R.id.iv_head));
        } else {
            ((CircleImageView) helper.getView(R.id.iv_head)).setImageResource(R.drawable.ic_default_head);
        }


        //是否被接单
        if (item.getUserStatus() == 2) {
            //未被接单
            helper.getView(R.id.tv_take).setBackground(ContextCompat.getDrawable(mContext, R.drawable.shouye_uxing));
            helper.setText(R.id.tv_take, "我要接单");
        } else {
            //已经被接单
            helper.getView(R.id.tv_take).setBackground(ContextCompat.getDrawable(mContext, R.drawable.shouye_wanhceng));
            helper.setText(R.id.tv_take, "已被接单");
        }
    }

}
